package org.tembli.euler.scala

/*
* PROBLEM 1: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. 
* The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.
*/
object Problem1 {
  def main(args: Array[String]) {
    // my first stab
    println (eval(3,1000) + eval(5,1000) - eval (15,1000))
    
    //idiomatic scala
    println ((1 until 1000).filter{i => (i % 3) == 0 || (i % 5 == 0)}.foldRight(0){(a,b) => a+b})
    
    println((1 until 10))
  }  

  def eval(m: Int, limit: Int): Int = {
    var f = 1
    var r = m
    var multiples:List[Int] = List()
    
    while (r < limit) {
      multiples = r :: multiples
      f = f + 1
      r = m * f
    }
    multiples.foldRight(0){(a,b) => a+b}
  }
}
